###FIRST RUN Study 1 Data Code.R###

####APPENDIX TABLE 1####
atable1 <- matrix(NA,24,6)

##FEDERAL CONSTITUTION
atable1[1,1:3] <- as.vector(unlist(t.test(study1$MALE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$MALE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[2,1:3] <- as.vector(unlist(t.test(study1$AGE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$AGE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[3,1:3] <- as.vector(unlist(t.test(study1$EDUCATION[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$EDUCATION[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[4,1:3] <- as.vector(unlist(t.test(study1$INCOME[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$INCOME[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[5,1:3] <- as.vector(unlist(t.test(study1$LIBCON[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$LIBCON[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[6,1:3] <- as.vector(unlist(t.test(study1$RISK[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$RISK[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[7,1:3] <- as.vector(unlist(t.test(study1$UNIONS[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$UNIONS[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[8,1:3] <- as.vector(unlist(t.test(study1$TAXES[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$TAXES[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[9,1:3] <- as.vector(unlist(t.test(study1$WORKS[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$WORKS[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[10,1:3] <- as.vector(unlist(t.test(study1$BLACK[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$BLACK[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[11,1:3] <- as.vector(unlist(t.test(study1$HISP[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$HISP[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[12,1:3] <- as.vector(unlist(t.test(study1$WHITE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$WHITE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))

##FEDERAL LAW
atable1[1,4:6] <- as.vector(unlist(t.test(study1$MALE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$MALE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[2,4:6] <- as.vector(unlist(t.test(study1$AGE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$AGE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[3,4:6] <- as.vector(unlist(t.test(study1$EDUCATION[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$EDUCATION[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[4,4:6] <- as.vector(unlist(t.test(study1$INCOME[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$INCOME[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[5,4:6] <- as.vector(unlist(t.test(study1$LIBCON[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$LIBCON[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[6,4:6] <- as.vector(unlist(t.test(study1$RISK[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$RISK[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[7,4:6] <- as.vector(unlist(t.test(study1$UNIONS[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$UNIONS[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[8,4:6] <- as.vector(unlist(t.test(study1$TAXES[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$TAXES[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[9,4:6] <- as.vector(unlist(t.test(study1$WORKS[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$WORKS[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[10,4:6] <- as.vector(unlist(t.test(study1$BLACK[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$BLACK[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[11,4:6] <- as.vector(unlist(t.test(study1$HISP[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$HISP[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[12,4:6] <- as.vector(unlist(t.test(study1$WHITE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==1 & study1$CONDITION == "LAW"],study1$WHITE[!is.na(study1$CB_FED_SQ) & study1$CB_FED_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))

##STATE CONSTITUTION
atable1[13,1:3] <- as.vector(unlist(t.test(study1$MALE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$MALE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[14,1:3] <- as.vector(unlist(t.test(study1$AGE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$AGE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[15,1:3] <- as.vector(unlist(t.test(study1$EDUCATION[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$EDUCATION[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[16,1:3] <- as.vector(unlist(t.test(study1$INCOME[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$INCOME[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[17,1:3] <- as.vector(unlist(t.test(study1$LIBCON[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$LIBCON[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[18,1:3] <- as.vector(unlist(t.test(study1$RISK[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$RISK[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[19,1:3] <- as.vector(unlist(t.test(study1$UNIONS[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$UNIONS[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[20,1:3] <- as.vector(unlist(t.test(study1$TAXES[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$TAXES[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[21,1:3] <- as.vector(unlist(t.test(study1$WORKS[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$WORKS[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[22,1:3] <- as.vector(unlist(t.test(study1$BLACK[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$BLACK[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[23,1:3] <- as.vector(unlist(t.test(study1$HISP[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$HISP[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))
atable1[24,1:3] <- as.vector(unlist(t.test(study1$WHITE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "CONSTITUTION"],study1$WHITE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "CONSTITUTION"])[c(5,3)]))

##STATE LAW
atable1[13,4:6] <- as.vector(unlist(t.test(study1$MALE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$MALE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[14,4:6] <- as.vector(unlist(t.test(study1$AGE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$AGE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[15,4:6] <- as.vector(unlist(t.test(study1$EDUCATION[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$EDUCATION[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[16,4:6] <- as.vector(unlist(t.test(study1$INCOME[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$INCOME[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[17,4:6] <- as.vector(unlist(t.test(study1$LIBCON[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$LIBCON[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[18,4:6] <- as.vector(unlist(t.test(study1$RISK[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$RISK[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[19,4:6] <- as.vector(unlist(t.test(study1$UNIONS[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$UNIONS[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[20,4:6] <- as.vector(unlist(t.test(study1$TAXES[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$TAXES[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[21,4:6] <- as.vector(unlist(t.test(study1$WORKS[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$WORKS[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[22,4:6] <- as.vector(unlist(t.test(study1$BLACK[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$BLACK[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[23,4:6] <- as.vector(unlist(t.test(study1$HISP[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$HISP[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
atable1[24,4:6] <- as.vector(unlist(t.test(study1$WHITE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==1 & study1$CONDITION == "LAW"],study1$WHITE[!is.na(study1$CB_ST_SQ) & study1$CB_ST_TREAT==0 & study1$CONDITION == "LAW"])[c(5,3)]))
########################
